var basePath = "/activity";


function selectApp(){
    var appId = $("#select_appId").val();   
    var url = basePath+"/activityDefinition/list?appId="+appId;
 
    $("#loadPage_definition_list").load(url);
    $("#loadPage_editDefinition").html("");
	//$("#iframe_editDefinition").attr("src","");
};

function  changeType(id){
	checkNum(id);
	var appId =Number($("#appId").val()) ;
	var modelId = Number($("#modelId").val());
	var type = Number($("#"+id).val()); 
	$("#activityType").val(appId*1000000000000 + modelId*1000000 + type);
};

function resetFrameSize(iframe){
	try{
		var bHeight = iframe.contentWindow.document.body.scrollHeight;
		var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
		var height = Math.max(bHeight, dHeight); 
		iframe.height =  height;
	}catch (ex){
		alert("哎呀！从计算iframe大小出错了");
	}
}

function  addActivityDefinition(){
	//alert("addActivityDefinition");
	//$("#activityDefinitionForm").submit();
	$("#activityDefinitionForm").ajaxSubmit({
		url:"/activity/activityDefinition/save.json",
		type:"post",
		success : function(data){
			if(data.returnMsg == null){
				//在异步提交成功后要做的操作
				selectApp();
				//alert(data.item.activityType);
				viewDefinition(data.item.activityType);				
			}else{
				alert(data.returnMsg);
			}
		}
	});
	/*
	jQuery.ajax({		 
		type: "POST",
		beforeSend: function(){
			//在异步提交前要做的操作
		},
		success: function(){
			var activityType = $("#activityType").val();
			//在异步提交成功后要做的操作
			//selectApp();
			//viewDefinition(activityType);
		}
	});
	*/
}


function  deleteDefinition(activityType){	
	if(!confirm("确定要删除吗？")) {
		return;
	}	
	var url=basePath+"/activityDefinition/delete?activityType="+activityType;
	//window.location.href=url;
}

function  viewDefinition(activityType){
	var url=basePath+"/activityDefinition/get?activityType="+activityType;
	$("#loadPage_editDefinition").load(url);
	//$("#iframe_editDefinition").attr("src",url);
	
}

function  newDefinition(){
	var appId = $("#select_appId").val();
	var url=basePath+"/activityDefinition/new?appId="+appId;
	$("#loadPage_editDefinition").load(url);
	//$("#iframe_editDefinition").attr("src",url);	
}

function  cleanHtml(id){
	$("#"+id).html('');
	//$("#iframe_editDefinition").attr("src",url);	
}
function  testTemplate(){
	$("#activityDefinitionForm").ajaxSubmit({
		url:"/activity/activityDefinition/testTemplate.json",
		type:"post",
		success : function(data){			
			if(data.return_msg == null){
				$("#templateTestResult").css("background-color","blanchedalmond");
				$("#templateTestResult").css("color","");
				$("#templateTestResult").html(data.result);
			}else{
				$("#templateTestResult").css("background-color","blanchedalmond");
				$("#templateTestResult").css("color","red");
				$("#templateTestResult").html(data.return_msg);
			}
			$("#viewHtml").show();
		}
	});
	//$("#iframe_editDefinition").attr("src",url);	
}

// 函数:值允许#id输入数字
function  checkNum(id){
	var demovalue=$("#"+id).val();		
	$("#"+id).val(demovalue.replace(/\D/g,"")) ; 
}

function  checkForm(){
	var demovalue=$("#"+id).val();		
	$("#"+id).val(demovalue.replace(/\D/g,"")) ; 
}
 